<template>
  <div class="cmt-container">
    <h4>发表评论</h4>
    <hr>
    <textarea placeholder="请输入要评论的内容，最多不要超过120个字" maxlength="120"></textarea>
    <mt-button type="primary" size="large">发表评论</mt-button>
    <!-- 评论列表去 -->

    <div class="cmt-list">
      <div class="cmt-item" v-for="(item,i) in cmtlist" :key="item.add_time">
        <div class="cmt-title">第{{i+1}}楼&nbsp;用户：{{item.user_name}}&nbsp;发表时间：{{item.add_time|dateFormat}}</div>
        <div class="cmt-content">{{item.content}}</div>
      </div>
      
      
    </div>

    <mt-button type="danger" size="large" plain @click="getMore">加载更多</mt-button>

  </div>
</template>

<script>
export default {
  data() {
    return {
      cmtlist:[],
      pageindex: 1,
      isover:false
    };
  },
  props: ["id"],
  created(){
    this.getComList()
  },
  methods: {
    async getComList() {
      if(this.isover) true
      const { data } = await this.$http.get(
        "/api/getcomments/" + this.id + "?pageindex=" + this.pageindex
      );
      if(data.status===0){
        if(data.message.length==0) return (this.isover=true)
        this.cmtlist=this.cmtlist.concat(data.message);
      }
    },
    getMore(){
      this.pageindex+=1;
      this.getComList()
    }
  }
  
};
</script>

<style lang="scss" scoped>
.cmt-container {
  textarea {
    margin: 0;
    font-size: 14px;
  }
  .cmt-list {
    margin: 5px 0;
    .cmt-item {
      .cmt-title {
        font-size: 14px;
        background-color: #ddd;
      }
      .cmt-content {
        font-size: 13px;
        text-indent: 2em;
        line-height: 25px;
      }
    }
  }
}
</style>

